/**
 * jims
 */
package com.jims.master.modules.patient.myAttention.service;

import java.util.List;

import com.jims.master.modules.patient.myAttention.dao.ElectronGroupConsultationDao;
import com.jims.master.modules.patient.myAttention.entity.ElectronGroupConsultation;
import com.jims.master.modules.patient.myAttention.entity.ElectronGroupConsultationInto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;

/**
 * 会诊Service
 * @author jct
 * @version 2018-06-07
 */
@Service
@Transactional(readOnly = true)
public class ElectronGroupConsultationService extends CrudService<ElectronGroupConsultationDao, ElectronGroupConsultation> {
	@Autowired
	private ElectronGroupConsultationIntoService electronGroupConsultationIntoService;

	public ElectronGroupConsultation get(String id) {
		return super.get(id);
	}
	
	public List<ElectronGroupConsultation> findList(ElectronGroupConsultation electronGroupConsultation) {
		return super.findList(electronGroupConsultation);
	}
	
	public Page<ElectronGroupConsultation> findPage(Page<ElectronGroupConsultation> page, ElectronGroupConsultation electronGroupConsultation) {
		return super.findPage(page, electronGroupConsultation);
	}
	
	@Transactional(readOnly = false)
	public int save(ElectronGroupConsultation electronGroupConsultation) {
		return super.save(electronGroupConsultation);
	}
	
	@Transactional(readOnly = false)
	public int delete(ElectronGroupConsultation electronGroupConsultation) {
		return super.delete(electronGroupConsultation);
	}

	@Transactional(readOnly = false)
	public int saveGroup(ElectronGroupConsultation electronGroupConsultation,String groupDocs) {
		ElectronGroupConsultation electronGroupConsultation1 =savezhu(electronGroupConsultation);
		int result = saveitem(electronGroupConsultation1,groupDocs);
		return result;
	}

	@Transactional(readOnly = false)
	public ElectronGroupConsultation savezhu(ElectronGroupConsultation electronGroupConsultation) {
		this.save(electronGroupConsultation);
		return electronGroupConsultation;
	}

	@Transactional(readOnly = false)
	public int saveitem(ElectronGroupConsultation electronGroupConsultation,String groupDocs) {
		String[] docs = groupDocs.split(",");
		for(int i=0;i<docs.length;i++){
			ElectronGroupConsultationInto electronGroupConsultationInto = new ElectronGroupConsultationInto();
			electronGroupConsultationInto.setDoctorId(docs[i]);
			electronGroupConsultationInto.setPatientId(electronGroupConsultation.getPatientId());
			electronGroupConsultationInto.setHuizhenId(electronGroupConsultation.getId());
			electronGroupConsultationInto.setConfim("0");
			electronGroupConsultationIntoService.save(electronGroupConsultationInto);
		}
		return docs.length;
	}

	public ElectronGroupConsultation getById(String id) {
		return dao.getById(id);
	}

	public List<ElectronGroupConsultation> getByDoc(String doctorId) {
		return dao.getByDoc(doctorId);
	}
}